package com.example.myxmpp;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;

import com.example.myxmpp.dbhelper.SmsOpenHelper;
import com.example.myxmpp.provider.ContactsProvider;
import com.example.myxmpp.provider.SmsProvider;

import org.junit.Test;
import org.junit.runner.RunWith;

import static androidx.test.InstrumentationRegistry.getContext;


@RunWith(AndroidJUnit4.class)
public class TextSmsProvider {

    @Test
    public void testInsert1() {
        //getContext.getContentResolver().insert();
       // Context appContext = InstrumentationRegistry.getContext();
        ContentValues values = new ContentValues();
        values.put(SmsOpenHelper.SmsTable.FROM_ACCOUNT,"13600000000@192.168.0.102");
        values.put(SmsOpenHelper.SmsTable.TO_ACCOUNT,"long@192.168.0.102");
        values.put(SmsOpenHelper.SmsTable.BODY,"今晚约吗？");
        values.put(SmsOpenHelper.SmsTable.STATUS,"offline");
        values.put(SmsOpenHelper.SmsTable.TYPE,"chat");
        values.put(SmsOpenHelper.SmsTable.TIME,System.currentTimeMillis());
        values.put(SmsOpenHelper.SmsTable.SESSION_ACCOUNT,"long@192.168.0.102");

        getContext().getContentResolver().insert(SmsProvider.URI_SMS,values);
    }

    @Test
    public void testDelete1() {
       // Context appContext = InstrumentationRegistry.getContext();
        getContext().getContentResolver().delete(SmsProvider.URI_SMS,SmsOpenHelper.SmsTable.FROM_ACCOUNT +"=?",new String[]{"13600000000@192.168.0.102"});

    }

    @Test
    public void testUpdate1() {
        //Context appContext = InstrumentationRegistry.getContext();
        ContentValues values = new ContentValues();
        values.put(SmsOpenHelper.SmsTable.BODY,"今晚约吗？你个大头");
        values.put(SmsOpenHelper.SmsTable.TIME,System.currentTimeMillis());
        values.put(SmsOpenHelper.SmsTable.SESSION_ACCOUNT,"long@192.168.0.102");
        getContext().getContentResolver().update(SmsProvider.URI_SMS,values,SmsOpenHelper.SmsTable.FROM_ACCOUNT + "=?",
                new String[]{"13600000000@192.168.0.102"});
    }

    @Test
    public void testQuery1() {
       // Context appContext = InstrumentationRegistry.getContext();
        Cursor c = getContext().getContentResolver().query(SmsProvider.URI_SMS,null,null,null,null);
        //得到所有的列
        int columnCount = c.getColumnCount();
        while(c.moveToNext()){
            for (int i=0;i<columnCount; i++) {
                Log.i("testQuery", "++++++++++++++++" + c.getString(i)+"+++++++");
            }
        }
    }


}
